package bitArithmetic;

public class offer003 {
    public int[] countBits(int n) {
        int[] nums = new int[n+1];
        nums[0]=0;
        for (int i = 1; i <=n; i++) {
            int temp=i;
            int count = 0;
            while(i != 0){
                i = i & (i - 1);
                count++;
            }
            nums[temp]=count;
            i=temp;
        }
        return nums;
    }

    public static void main(String[] args) {
        offer003 offer003 = new offer003();
        int[] ints = offer003.countBits(2);
        for (int a :
                ints) {
            System.out.println(a);

        }
    }
}
